//
//  main.cpp
//  DataStructure
//
//  Created by 舒磊明 on 2020/4/1.
//  Copyright © 2020 Shuleiming. All rights reserved.
//

#include <iostream>
#include <ctime>
#include <string.h>

#include "SString/SString.hpp"
#include "Tree/Tree.hpp"

#define random(a,b) (rand() % (b-a+1)) + a

using namespace std;

// 打印数组
void printArray(int *a, int len)
{
    for (int i = 0; i < len; i++) {
        cout << a[i] << ' ';
    }
    cout << endl;
}

void FundCalculator()
{
    int year = 2020;
    long int money = 50000;
    int peryear = 0;
    double rate = 0.05;
    cout << "年利率" << rate * 100 << "%每月定投¥" << peryear / 12 <<endl;
    for (int i = 1; i <= 30; i++) {
        cout << year << "年:" << money / 10000 << "万，定投年数" << i << endl;
        money += peryear;
        money = money * rate + money;
        year++;
    }
}

void BSTMidOrder(BSTree T)
{
    if (T != nullptr) {
        BSTMidOrder(T->lchild);
        printf("%d ", T->data);
        BSTMidOrder(T->rchild);
    }
}

// 计算光伏板工作电流和开路电压
void va1(int merge, int string, int v, int a)
{
    int vv = v * string;
    int aa = a * merge;
    cout << merge << "并" << string << "串：";
    cout << "电压：" << vv << "V" << ", ";
    cout << "电流：" << aa << "A" << endl;
}

struct TreeNode {
    int val;
    struct TreeNode *left, *right;
};

typedef struct QNode {
    struct TreeNode *node;
    struct QNode *next;
} TQNode;

typedef struct {
    TQNode *rare, *front;
} TQueue;

// 初始化队列
void InitQueue(TQueue &Q)
{
    TQNode *s = (TQNode*)malloc(sizeof(TQNode));
    s->next = nullptr;
    Q.front = s;
    Q.rare = Q.front;
}

// 入队
bool EnQueue(TQueue &Q, struct TreeNode *s)
{
    TQNode *n = (TQNode*)malloc(sizeof(TQNode));
    n->node = s;
    n->next = nullptr;
    Q.rare->next = n;
    Q.rare = n;
    return true;
}

// 出队
bool DeQueue(TQueue &Q, struct TreeNode *node)
{
    if (Q.front == Q.rare) return false;
    TQNode *p = Q.front->next;
    Q.front->next = p->next;
    if (Q.rare == p) Q.rare = Q.front;
    node = p->node;
    free(p);
    return true;
}

// 判空
bool QueueEmpty(TQueue Q)
{
    return Q.rare == Q.front;
}

int rob(struct TreeNode* root){
    // 要么偷奇数行，要么偷偶数行
    int rob = 0, rob2 = 0;    // 偷窃总金额
    TQueue Q1, Q2; // 保存奇数和偶数行的队列
    struct TreeNode *p = nullptr; // 指向出队结点的指针
    InitQueue(Q1);InitQueue(Q2);
    EnQueue(Q1, root);
    while (!QueueEmpty(Q1)) {
        DeQueue(Q1, p);
        rob += p->val;
        if (p->left) EnQueue(Q2, p->left);
        if (p->right) EnQueue(Q2, p->right);
        while (!QueueEmpty(Q2)) {
            DeQueue(Q2, p);
            rob2 += p->val;
            if (p->left) EnQueue(Q1, p->left);
            if (p->right) EnQueue(Q1, p->right);
        }
    }
    return rob > rob2 ? rob : rob2;
}

// 小写转为大写
void translate(char str[])
{
    char *p = str;
    
    while (*p != '\0') {
        if ((int)*p >= (int)'a' && (int)*p <= (int)'z') {
            *p += 'A' - 'a';
        }
        p++;
    }
    printf("%s\n", str);
}

int main(int argc, const char * argv[]) {
//    int arr[] = {0,4,5,2,23,51,3,54,65};
//    int len = sizeof(arr) / sizeof(int);
    return 0;
}
